package com.example.base.checker;

import com.example.base.entity.UserDormRelation;
import com.example.base.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class NotChoosedImpl implements ConstraintValidator<NotChoosed, String> {

    @Autowired
    private UserService userService;

    @Override
    public void initialize(NotChoosed constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        UserDormRelation relation = userService.getRelationByUid(s);
        return relation == null;
    }
}
